<?php


namespace App\Admin\Actions;

use App\Models\AdminUser;
use Encore\Admin\Grid\Displayers\Actions;

class RowAction extends \Encore\Admin\Actions\RowAction
{
    public function __construct($actions = null, $name = null)
    {
        if ($actions instanceof Actions) {
            $this->setGrid($actions->getGrid())->setRow($actions->row);
        }
        $name and $this->name = $name;
        parent::__construct();
    }

    public function name(): string
    {
        return <<<HTML
    {$this->name}
HTML;
    }

    public function authorize(AdminUser $user, $model): bool
    {
        return $user->role_type == 1;
    }

    public function __toString()
    {
        return $this->render();
    }

}
